<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IE和FF下的事件模型对比</title>
<style>
body{
	width:90%;
}
#d1{
	width:60%;
	height:18em;
	padding:20px;
	margin:50px auto 0 auto;
	background-color:#DDD;
}
#i{
	margin-top:20px;
	ime-mode:disabled;
}
#s{
	/*background-color:grey;*/
	border: 1px dashed red;
	padding:1px 10px;
	margin-left:20px;
}
</style>
</head>

<body>
	<div id="d1">
		<input type="text" id="i"></input>
		<span id="s">你输入的是：<strong id="st"></strong></span>
		<br /><br /><hr />
		<pre><code>
//IE下的事件对象是定义在全局的属性，window.event上，而FF的作用域是在事件函数内。
document.getElementById("i").onkeypress = function(){
	var e = window.event;
	if(!e){
		alert("请使用IE");
		return false;
	}
	document.getElementById("st").innerHTML = String.fromCharCode(e.keyCode);
}
	</code></pre>
	</div>
	
</body>
<script>
get("i").onkeypress = function(){
	var e = window.event;
	if(!e){
		alert("请使用IE");
		return false;
	}
	var str = String.fromCharCode(e.keyCode);
	this.value = str
	get("st").innerHTML = str;
}
function get(id){
	return document.getElementById(id);
}
</script>
</html>
